﻿Chenxin.UI.CommisionDetail = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/CommisionDetail.ashx',
    createSearch: function() {
        return new Chenxin.UI.CommisionDetailSearch({
            scope: this
        });
    },
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.MultiRowGrid({
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
}];
                },
                actionUrl: this.actionUrl + '?op=getlist',
                id: 'search_table',
                renderTo: 'search_table',
                hasCheckBox: false,
                modelId: 'ContractId',
                height: 300,
                cellBorder: true,
                autoLoad: false,
                scope: this,
                columns: {
                    business: {
                        head: '商圈',
                        width: 120
                    },
                    BuyerDepartName: {
                        head: '门店',
                        width: 120,
                        sortable: true
                    },
                    ContractDate: {
                        head: '成交日期',
                        width: 80,
                        renderer: function(val, field, row) {
                            return val.split(' ')[0];
                        }
                    },
                    ContractCode: {
                        head: '成交编号',
                        width: 120
                    },
                    HouseAddress: {
                        head: '地址',
                        width: 300
                    },
                    ConfirmEmplyee: {
                        head: '编号发放人员',
                        width: 120
                    },
                    CreateArchEmp: {
                        head: '业绩确认人员',
                        width: 120,
                        renderer: function(val, field, row) {
                            if (val.length < 1)
                                return '-';
                            else
                                return val;
                        }
                    },
                    Depart: {
                        width: 180,
                        items: {
                            VDepartName: {
                                width: 180,
                                head: '上家门店',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BDepartName: {
                                width: 180,
                                head: '下家门店',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    UserName: {
                        width: 180,
                        items: {
                            VUserName: {
                                width: 180,
                                head: '上家业务员',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BUserName: {
                                width: 180,
                                head: '下家业务员',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    StanCommision: {
                        width: 100,
                        items: {
                            VStanCommision: {
                                width: 100,
                                head: '上家标准佣收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BStanCommision: {
                                width: 100,
                                head: '下家标准佣收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    RealCommision: {
                        width: 100,
                        items: {
                            VRealCommisionFinal: {
                                width: 100,
                                head: '上家确认佣收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BRealCommisionFinal: {
                                width: 100,
                                head: '下家确认佣收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    Commision: {
                        width: 100,
                        items: {
                            VCommisionFinal: {
                                width: 100,
                                head: '上家折佣',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BCommisionFinal: {
                                width: 100,
                                head: '下家折佣',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    Consulting: {
                        width: 100,
                        items: {
                            VConsultingFinal: {
                                width: 100,
                                head: '上家咨询费',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BConsultingFinal: {
                                width: 100,
                                head: '下家咨询费',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    STDiscountFinal: {
                        width: 100,
                        items: {
                            VSTDiscountFinal: {
                                width: 100,
                                head: '上家特殊折佣'
                            },
                            BSTDiscountFinal: {
                                width: 100,
                                head: '下家特殊折佣'
                            }
                        }
                    },
                    CommisionGeted: {
                        width: 100,
                        items: {
                            VCommisionGeted: {
                                width: 100,
                                head: '上家实收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BCommisionGeted: {
                                width: 100,
                                head: '下家实收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    UnGeted: {
                        width: 100,
                        items: {
                            VUnGeted: {
                                width: 100,
                                head: '上家未收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            },
                            BUnGeted: {
                                width: 100,
                                head: '下家未收',
                                renderer: function(val, field, row) {
                                    if (val.length < 1)
                                        return '-';
                                    else
                                        return val;
                                }
                            }
                        }
                    },
                    DealDate: {
                        head: '账龄',
                        width: 80,
                        renderer: function(val, field, row) {
                            if (val.length < 1)
                                return '-';
                            else
                                return val;
                        }
                    },
                    ArchivementDate: {
                        head: '业绩归属时间',
                        width: 100
                    },
                    HasFollow: {
                        head: '未收跟进',
                        width: 220
                    },
                    BargainCompanyName: {
                        head: '合同归属公司',
                        width: 180
                    }
                }
            });
        },
        initEvent: function() {
            var _this = this;
            $("#aReply").click(function() {
                if (!_this.currentId) {
                    alert('请先选择一条记录！');
                    return;
                }
                _this.loadInfo();
                _this.loadRemark();
                _this.contractRemarkInfo();
            });
        },
        loadInfo: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: '/service/logic/ShowListContract.ashx',
                data: { op: 'getmodel', modelid: this.currentId },
                onSuccess: function(data, msg) {
                    if (data) {
                        _this.currentInfo = data.model;
                        _this.currentContractInfo = data.model1;

                    }
                }
            });
        },
        loadRemark: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: '/service/logic/ShowRemarkInfo.ashx',
                data: { op: 'searchRemark', modelid: this.currentId },
                onSuccess: function(data, msg) {
                    if (data) {
                        _this.currentRemark = data;
                    }
                }
            });
        },
        exportAll: function() {
            _this = this;
            paramStr = this.search.getParamJson();
            paramStr.op = 'exportAll';
            Chenxin.Msg.Waiting.show();
            Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
            //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
            Chenxin.Msg.Waiting.hide();
        },
        //未收佣收跟进
        contractRemarkInfo: function() {
            var _this = this;
            if (!this.RemarkInfoFrm) {
                this.RemarkInfoFrm = new Chenxin.UI.RemarkInfoForm({
                    scope: this,
                    op: 'addCommision',
                    title: '未收佣收跟进',
                    url: "/service/logic/ShowRemarkInfo.ashx",
                    data: { op: 'searchRemark', ContractId: this.currentId },
                    afterGetFormJson: function(json) {
                        json.Status = 20;
                        delete json.HouseAddress;
                        delete json.ContractCode;
                    },
                    saveSucc: function() {
                        _this.grid.reload();
                    }
                });
            }
            if (this.RemarkInfoFrm.show()) {
                var _data = this.currentInfo;
                var _remark = this.currentRemark;
                this.RemarkInfoFrm.fitData(_data);
                this.RemarkInfoFrm.grid.clear();
                this.RemarkInfoFrm.grid.render(_remark);
            }
        },
        initComponent: function() {
            Chenxin.UI.CommisionDetail.superclass.initComponent.call(this);
            //this.searchGrid();
        }
    });

/**
*查询面板
*/
Chenxin.UI.CommisionDetailSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'search',
    initEvent: function() {
        var _this = this;
        /*************************事件：起始日期得到焦点************************/
        $('#keyword').defText({
            deftxt: '输入成交编号/地址'
        });

        //查询按钮
        $('#btn_search').click(function() {
            _this.scope.searchGrid();
        });
		
		/********事件：实收归属日期******/
        $("#ArcTimes").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy.MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
		
		$("#ArcTimee").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy.MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        //var curdate = new Date();
        //$('#ArcTimes').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));
    },
    createComboList: function() {
        var combl = new Chenxin.UI.StructComboList({
            tbxWidth: 55,
            cityAfterSelected: function() {
                comboUserId.reset();
            },
            companyAfterSelected: function() {
                comboUserId.reset();
            },
            businessDistrictAfterSelected: function() {
                comboUserId.reset();
            },
            departsAfterSelected: function(val) {
                comboUserId.reset();
                if (val != '请选择') {
                    comboUserId.loadUser(val, 500);
                }
            }
        });
        //日期类型
        var cmbDateType = new Chenxin.UI.Combo({
            containerId: '#datetype',
            tbxWidth: 75,
            colWidth: 80,
            //initValue: 'PayArchDate',
            name: 'datetype',
            addPleaseSelected:false,
            items: [{ txt: '实收归属日期', val: 'PayArchDate' }, { txt: '业绩归属日期', val: 'ContractArchDate'}]
        });

        //状态
        var cmbtype = new Chenxin.UI.Combo({
            containerId: '#status',
            tbxWidth: 45,
            name: 'status',
            initValue:'10',
            items: [{ txt: '未收齐', val: '10' }, { txt: '已收齐', val: '20' }, { txt: '未确认', val: '30' }, { txt: '全部', val: '0'}],
			onSelected:function(){
				var val=this.getValue();
				var dIpt=$('#overtime');
				if(val=='10'||val=='20'){
					dIpt.enable();
					dIpt.val('');
				}else{
					dIpt.val('');
					dIpt.disable();					
				}
			}
        });

        //合同归属（城市）
        var comboBargainCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#BargainCityId',
            name: 'BargainCityId',
            tbxWidth: 45,
            inModelType: 'all',
            txtModelName: 'BargainCityName',
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboBargainCompanyId.clearItems();
                } else {
                    comboBargainCompanyId.param.fatherid = this.getValue();
                    comboBargainCompanyId.reload();
                }
            }
        });
        //合同归属（公司）
        var comboBargainCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#BargainCompanyId',
            name: 'BargainCompanyId',
            inModelType: 'all',
            tbxWidth: 65,
            autoLoad: false
        });

        //人员
        var comboUserId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtUser',
            inModelType: 'all',
            txtModelName: 'UserName',
            singleSelect: true,
            name: 'UserId'
        });

        var structs = combl.comboList;
        structs.push(cmbDateType);
        structs.push(cmbtype);
        structs.push(comboBargainCompanyId);
        structs.push(comboUserId);
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.CommisionDetailSearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function() {
    var CommisionDetail = new Chenxin.UI.CommisionDetail();
});